<template>
  <div>
    <wx-tables
      :columns="columns"
      title="租赁标的维护"
      :data-source="dataSource"
      :loading="loading"
      :total="total"
      :page.sync="page"
    >
      <template #search>
        <tip-block tip="搜索" />
        <el-form label-position="left" style="margin-top: 10px;">
          <el-row :gutter="20">
            <el-col :span="4">
              <el-form-item prop="search_code">
                <el-input v-model="searchForm.search_code" placeholder="请输入标的编码" />
              </el-form-item>
            </el-col>
            <el-col :span="2">
              <el-button type="primary" class="table-btn" icon="el-icon-search" @click="handleSearchClick">查询</el-button>
            </el-col>
          </el-row>
        </el-form>
      </template>
      <!-- tools -->
      <template #tools>
        <el-button type="primary" class="table-btn" icon="el-icon-plus" @click="handleOpenMyForm()">新增</el-button>
        <el-button class="table-btn" icon="el-icon-refresh-right" @click="handleGetTable">刷新</el-button>
      </template>
      <!-- table slots -->
      <template v-slot:company_id="{ row }">
        <span>{{ row.company && row.company.company_name }}</span>
      </template>
      <template v-slot:admin_id="{ row }">
        <span>{{ row.admin && row.admin.name }}</span>
      </template>
      <template v-slot:oper="record">
        <div class="oper-box">
          <span><el-link type="primary" @click="handleOpenMyForm(record.row.id)">编辑</el-link></span>
          <el-popconfirm
            :ref="`popover-${record.$index}`"
            title="确定删除当前所选项吗？"
            @confirm="handleDelByKey(record.row.id)"
          >
            <el-link slot="reference" type="danger">删除</el-link>
          </el-popconfirm>
        </div>
      </template>
    </wx-tables>

    <wx-full :title="fullMyTitle" :visible.sync="formVisible">
      <template v-slot:tools>
        <el-link v-if="isAdd" type="primary" :disabled="formBtnDisabled" @click="handleSaveDraft">保存草稿</el-link>
        <el-link v-else type="primary" :disabled="formBtnDisabled" @click="handleSaveMyForm">保存</el-link>
      </template>
      <leased-object-form ref="myForm" :loading="formLoading" :is-add="isAdd" />
    </wx-full>
  </div>
</template>

<script>
const TITLE = '租赁标的维护'
import LeasedObjectForm from './Form'
import WxFull from '@/components/WxFull'
import WxTables from '@/components/WxTables'
import FullMixins from '@/components/WxTables/fullMixins'
import TableMixins from '@/components/WxTables/mixins'
import TipBlock from '@/components/TipBlock'
const DEFULTWIDTH = { 'min-width': 150 }
export default {
  name: 'LeasedObject',
  components: {
    WxTables,
    WxFull,
    LeasedObjectForm,
    TipBlock
  },
  mixins: [TableMixins, FullMixins],
  data() {
    return {
      markId: 'leased_object_id',
      TITLE,
      columns: [
        { dataIndex: 'code', label: '租赁标的编码', config: DEFULTWIDTH },
        { dataIndex: 'name', label: '租赁标的名称', config: DEFULTWIDTH },
        { dataIndex: 'type', label: '租赁标的类型', config: DEFULTWIDTH },
        { dataIndex: 'company_id', label: '所属公司', config: DEFULTWIDTH },
        { dataIndex: 'rental_area', label: '计租面积(平方米)', config: DEFULTWIDTH },
        { dataIndex: 'cost_center_code', label: '关联成本中心', config: DEFULTWIDTH },
        { dataIndex: 'address', label: '所在地址', config: DEFULTWIDTH },
        { dataIndex: 'created_at', label: '单据创建日期', config: DEFULTWIDTH, time: true },
        { dataIndex: 'admin_id', label: '单据人', config: DEFULTWIDTH },
        { dataIndex: 'oper', label: '操作', slots: true, config: { fixed: 'right', ...DEFULTWIDTH }}
      ],
      api: '/api/adminPortal/leasedObject/getListByCon',
      findApi: '/api/adminPortal/leasedObject/getById',
      baseApi: '/api/adminPortal/leasedObject/'
    }
  }
}
</script>
